<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta name="generator" content=
  "HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />

  <title>SystemPropertiesPicoContainer</title>
</head>

<body>
  <p>SystemPropertiesPicoContainer is a special type of
  PicoContainer that is populated from the <a href=
  "http://www.mindspring.com/~mgrand/java-system-properties.htm">System
  Properties</a> passed into the Java application when it
  started.</p>

  <p>Here is an example of how to use SystemPropertiesPicoContainer
  to map system properties as configuration for a component, with
  parameter names as the bindings.</p>

  <p>Consider this component:</p>

  <div class="source">
    <pre>
public class BigFatComponent {
  URL spellWebService;
  int timeout;
  public BigFatComponent(String spellingWebServiceURL, int timeout) throws MalformedURLExeption {
    this.spellWebService = new URL(spellingWebServiceURL);
    this.timeout = timeout;
  }  
  public String toString() {
    return "URL=" + spellWebService + ", timeout=" + timeout;  
  }

  // other methods
}

</pre>
  </div>

  <p>For automatic binding of system properties to parameter names
  of the component:</p>

  <div class="source">
    <pre>
PicoContainer syspropsContainer = new SystemPropertiesPicoContainer();
                
MutablePicoContainer mpc = new DefaultPicoContainer(syspropsContainer);
                
mpc.as(Characteristics.USE_NAMES).addComponent(BigFatComponent.class);
</pre>
  </div>

  <p>Here is another manual use forcing an association between a
  system properties, and the relative position of a parameter in
  the constructor. It is most useful when there is not a tie-up
  between the parameter names and the system properties. In this
  case the arg passed in to the ConfigParameter (varargs list) is
  the one that matches the syst property name:</p>

  <div class="source">
    <pre>
mpc.addComponent(BigFatComponent.class, ConfigParameter("wsURL"), ConfigParameter("serviceTimeout"));
</pre>
  </div>

  <p>System properties can be set for the scope of the application
  only, as you start the application:</p>

  <div class="source">
    <pre>
java -Dwebservice.url=http://servicehost/service -Dwebservice.timeout=50 -jar myAppJar.jar -cp picocontainer-2.0.jar
</pre>
  </div>

  <p>Type conversion is automatic in many cases. Properties in a
  properties file are clearly strings. Parameters can be any
  of:</p>

  <ul>
    <li>String</li>

    <li>All numeric types, boxed as well as primitives</li>

    <li>java.util.Date</li>

    <li>java.io.File as well as java.io.URL</li>

    <li>java.util.Date</li>

    <li>java.sql.(Date|Time|Timestamp)</li>

    <li>Any type sporting accessible constructor taking single
    string parameter.</li>
  </ul>

  <p>SystemPropertiesPicoContainer can be part of a tree of
  containers. It makes sense, of course, being more near the root
  of that tree.</p>
</body>
</html>
